package pipeline;

import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import repository.HBaseRepository;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import java.io.IOException;
import java.net.URISyntaxException;

public class LianJiaPipeline implements Pipeline {

    private static Logger logger = LoggerFactory.getLogger(LianJiaPipeline.class);

    private HBaseRepository hBaseRepository;

    public LianJiaPipeline(){
        try {
            hBaseRepository = new HBaseRepository();
        } catch (URISyntaxException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void process(ResultItems resultItems, Task task) {
        JSONObject row = resultItems.get("row");
        try {
            hBaseRepository.putColumn(row);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
